//
//  XFMessageTableViewCell.m
//  sharedBooks
//
//  Created by 赖国锋 on 2016/11/20.
//  Copyright © 2016年 XunFengKJ. All rights reserved.
//

#import "XFMessageTableViewCell.h"
#import "XFMessageModel.h"
@interface XFMessageTableViewCell ()

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightConstraint;

@end

@implementation XFMessageTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectionStyle = 0;
    self.timeLabel.font = [UIFont systemFontOfSize:13];
    self.timeLabel.textColor = XFUIColorFromRGB(0x333333);
    self.messageLabel.textColor = XFUIColorFromRGB(0x666666);
    self.messageLabel.font = [UIFont systemFontOfSize:16];
    [self setLabelAdjustWithLabel:self.messageLabel];
}

-(void)setModel:(XFMessageModel *)model{
    _model = model;
    self.timeLabel.text = model.createtime;
    self.message = model.content;
}

//根据宽度计算cell的高度
-(void)setMessage:(NSString *)message{
    _message = message;
    self.messageLabel.text = message;
    CGRect nowFrame = [message boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 32, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16],NSForegroundColorAttributeName:[UIColor redColor]} context:nil];
    self.heightConstraint.constant = nowFrame.size.height+8;
}

-(void)setLabelAdjustWithLabel:(UILabel*)label{
    
    label.textAlignment = NSTextAlignmentLeft;
    label.lineBreakMode = NSLineBreakByWordWrapping;
    label.numberOfLines = 0;
}

@end
